<?php
namespace Home\Controller;
use Common\Controller\CommonController;
use Common\Model\BannerModel;
class IndexController extends HomeController {
 	public function _initialize(){
 		parent::_initialize();
 	}
    //轮播
	//首页最新价
 	public function getNewPrice(){  
 	    $usermoney= M('Member_money')->where(['member_id'=>$this->uid])->find();
 	    //VIC最新价
 	    $vic_price=M('Config')->where(['id'=>'1'])->find()['value'];;
 	    //VIC开启数量
 	    $vic_open_num = M('Project_log')->where(['uid'=>$this->uid,'type'=>1])->sum('money');
 	    $list['vic_price'] = $vic_price*($usermoney['money1']+$vic_open_num);
 	    $price_list = $this->getPrice();
 	    //dump($price_list);die;
 	    //比特币最新价
 	    $btc_price=$price_list['price_btc'];
 	    //开启数量
 	    $btc_open_num = M('Project_log')->where(['uid'=>$this->uid,'type'=>2])->sum('money');
 	    $list['btc_price'] = $btc_price*($usermoney['money2']+$btc_open_num);
 	    //以太坊最新价
 	    $eth_price=$price_list['price_eth'];
 	     //开启数量
 	     $eth_open_num = M('Project_log')->where(['uid'=>$this->uid,'type'=>3])->sum('money');
 	     $list['eth_price'] = $eth_price*($usermoney['money3']+$eth_open_num);
 	     //PAI最新价
 	     $pai_price=$price_list['price_eos'];
 	     //PAI开启数量
 	     $pai_open_num = M('Project_log')->where(['uid'=>$this->uid,'type'=>4])->sum('money');
 	     $list['pai_price'] = $pai_price*($usermoney['money4']+$pai_open_num);
 	     //$btc_open_num = $btc_open_num?$btc_open_num:0.00;
		 $list['money_vic'] = $usermoney['money1']+round($vic_open_num,4);
		 $list['money_btc'] = $usermoney['money2']+ round($btc_open_num,4);
		 $list['money_eth'] = $usermoney['money3']+round($eth_open_num,4);
		 $list['money_pai'] = $usermoney['money4']+round($pai_open_num,4);
		 
		 $list['money_vic'] = round($list['money_vic'],4);
		 $list['money_btc'] = round($list['money_btc'],4);
		 $list['money_eth'] = round($list['money_eth'],4);
		 $list['money_pai'] = round($list['money_pai'],4);
 	     /* //团队奖
 	     $table = $this->getMemberGroup(intval($this->uid));
 	     //总返利
 	     $where_zong['uid'] = $this->uid;
 	     $zong_shouyi = M('Project_auto_money')->where($where_zong)->sum('money');
 	     //总团队奖
 	     $where_tuandui['member_id'] = $this->uid;
 	     $where_tuandui['currency_id'] = 1001;
 	     $zong_tuandui = M('Finance_'.$table)
 	     ->where($where_tuandui)
 	     ->sum('money');
 	     $list['zong'] = $zong_shouyi+$zong_tuandui;
 	     //团队奖
 	     $table = $this->getMemberGroup(intval($this->uid));
 	     //比特币总返利
 	     $where_fanli_btc['member_id'] = $this->uid;
 	     $where_fanli_btc['currency_id'] = 11;
 	     $where_fanli_btc['type'] = 1;
 	     $zong_fanli_btc = M('Finance_'.$table)
 	     ->where($where_fanli_btc)
 	     ->sum('money');
 	     //以太坊总返利
 	     $where_fanli_eth['member_id'] = $this->uid;
 	     $where_fanli_eth['currency_id'] = 11;
 	     $where_fanli_eth['type'] = 2;
 	     $zong_fanli_eth = M('Finance_'.$table)
 	     ->where($where_fanli_eth)
 	     ->sum('money');
 	     //比特币总返利
 	     $where_tuandui_btc['member_id'] = $this->uid;
 	     $where_tuandui_btc['currency_id'] = 1001;
 	     $where_tuandui_btc['type'] = 1;
 	     $zong_tuandui_btc = M('Finance_'.$table)
 	     ->where($where_tuandui_btc)
 	     ->sum('money');
 	     //以太坊总团队奖
 	     $where_tuandui_eth['member_id'] = $this->uid;
 	     $where_tuandui_eth['currency_id'] = 1001;
 	     $where_tuandui_eth['type'] = 2;
 	     $zong_tuandui_eth = M('Finance_'.$table)
 	     ->where($where_tuandui_eth)
 	     ->sum('money');
 	     $list['shouyi_btc'] = number_format($zong_fanli_btc+$zong_tuandui_btc,4);
 	     $list['shouyi_eth'] = number_format($zong_fanli_eth+$zong_tuandui_eth,4); */
 	    $list['status'] = 1;
 	    $this->ajaxReturn($list);
 	}
 	//一条公告
 	public function getOneNotice(){
 	    $language = $_SERVER['HTTP_LANGUAGE']?$_SERVER['HTTP_LANGUAGE']:'';
 	    $article = M('Notice');
 	    $list = $article->order('add_time desc')->find();//时间降序排列，越接近当前时间越高
 	    if($language){
 	        if($language=='ko'){
 	            $language='kor';
 	        }
     	    $lan = language($list['title'], 'zh', $language);
     	     foreach ($lan as $k => $v)
     	    {
     	        $list['title'] = ucwords($v->dst) ."\n";
     	    } 
 	    }
 	    $return['data'] = $list;
 	    $return['status'] = 1;
 	    $this->ajaxReturn($return);
 	}
 	public function index(){
 		$this->display();
 	}
 	public function qrcode() {
 		Vendor('phpqrcode.phpqrcode');//这个很重要，没引用则不能使用
 		$value = 'asdasd'; //二维码内容
 		$errorCorrectionLevel = 'L'; //容错级别
 		$matrixPointSize = 4; //生成图片大小
 		//生成二维码图片
 		\QRcode::png($value, 'qrcode.jpg', $errorCorrectionLevel, $matrixPointSize, 2);//之前做的时候少了一个'\'，会显示没有此类
 		$logo = 'bch.png'; //准备好的logo图片 ；引用文件地址同样很重要，我犯了引入地址错误，结果最后的二维码中间没有图片
 		$QR = 'qrcode.jpg'; //已经生成的原始二维码图
 		if ($logo !== FALSE) {  
			  $QR = imagecreatefromstring(file_get_contents($QR));  
			  $logo = imagecreatefromstring(file_get_contents($logo));  
			  $QR_width = imagesx($QR);//二维码图片宽度  
			  $QR_height = imagesy($QR);//二维码图片高度  
			  $logo_width = imagesx($logo);//logo图片宽度  
			  $logo_height = imagesy($logo);//logo图片高度  
			  $logo_qr_width = $QR_width / 5;  
			  $scale = $logo_width/$logo_qr_width;  
			  $logo_qr_height = $logo_height/$scale;  
			  $from_width = ($QR_width - $logo_qr_width) / 2;  
			  //重新组合图片并调整大小  
			  imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,  
			  $logo_qr_height, $logo_width, $logo_height);  
			} 
			$url= './ercode/111.png';
			//输出图片  
			imagepng($QR, './ercode/111.png');
			echo substr($url, 1); 
 	
 	}
}